package com.jt.provider.interceptor;

import com.sun.xml.internal.ws.policy.privateutil.RuntimePolicyUtilsException;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalTime;

public class Interceptor implements HandlerInterceptor {
    /**
     * preHandle
     * 基于访问事件进行请求的放行和终止
     * */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("我是第一层拦截，不是晚上我就让你过去了"); //表示拦截
        LocalTime now = LocalTime.now();  //返回一个当前时间对象
        int hour = now.getHour();  //获取小时
        if(hour<8||hour>=18){
            throw new RuntimeException("请在规定时间访问");
        }
        return true;  //表示请求到此结束，不再进行传递
    }
}
